﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using phudieuhungthinh.BL;
using phudieuhungthinh.BL.Model;


namespace phudieuhungthinh.Admin
{
    public partial class ProductList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        [WebMethod(EnableSession = true)]
        public static object GetProductList()
        {
            try
            {
                //Get data from database
                ProductImpl productImpl = new ProductImpl();
                List<ProductModel> listProductModel = new List<ProductModel>();
                listProductModel = productImpl.GetProductList();

                //Return result to jTable
                return new { Result = "OK", Records = listProductModel, TotalRecordCount = listProductModel.Count };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }      

        [WebMethod(EnableSession = true)]
        public static bool DeleteProduct(int productId)
        {
            try
            {
                //Delete a product in database.
                ProductImpl productImpl = new ProductImpl();
                var record = productImpl.GetProductInfo(productId);
                productImpl.DeleteProduct(record);
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}